package com.lw.sbdemo2.web;

import com.lw.sbdemo2.common.base.BaseController;
import com.lw.sbdemo2.common.utils.IdUtils;
import com.lw.sbdemo2.common.vo.PageInfo;
import com.lw.sbdemo2.common.web.anno.Required;
import com.lw.sbdemo2.common.web.anno.ResultController;
import com.lw.sbdemo2.entity.TkGradeDict;
import com.lw.sbdemo2.service.TkGradeDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

/**
 * <p>标题: 年级字典服务 - 请求控制层</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2019</p>
 * <p>公司: 山人行工作室</p>
 *
 * @version: 1.0
 * @author: Linqunyuan
 * @date 2019-5-25
 */
@ResultController
@Api(description = "TkGradeDictController", tags = {"年级字典服务"})
@RequestMapping(value = "/tkGradeDict")
public class TkGradeDictController extends BaseController {

    /**
     * 年级字典服务
     */
    @Autowired
    private TkGradeDictService tkGradeDictService;
	
	@ApiOperation(value = "获取年级字典列表")
    @GetMapping("")
    public List<TkGradeDict> findList(TkGradeDict tkGradeDict) {
        return tkGradeDictService.findList(tkGradeDict);
    }

    @ApiOperation(value = "获取年级字典列表（分页）", response = PageInfo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "关键词", dataType = "string"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int"),
    })
    @GetMapping(value = "/page")
    public PageInfo<TkGradeDict> page(String query, @Required("pageNum") PageInfo pageInfo, TkGradeDict tkGradeDict) {
        return tkGradeDictService.findListPage(query, pageInfo, tkGradeDict);
    }

    @ApiOperation(value = "获取年级字典详细信息", notes = "根据url的id来获取年级字典详细信息")
    @ApiImplicitParam(name = "id", value = "年级字典ID", required = true, dataType = "String")
    @GetMapping("/{id}")
    public TkGradeDict get(@PathVariable String id) {
        return tkGradeDictService.getById(id);
    }

    @ApiOperation(value = "创建年级字典")
    @PostMapping("/insert")
    public void insert(TkGradeDict tkGradeDict) throws Exception {
		tkGradeDict.setCreatedTime(new Date());
        tkGradeDict.setGradeId(IdUtils.uuid());
        tkGradeDictService.checkName(tkGradeDict.getGradeName());
        tkGradeDictService.insert(tkGradeDict);
    }

    @ApiOperation(value = "更新年级字典详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "年级字典ID", required = true, paramType = "query", dataType = "String")
    })
    @PostMapping("/update")
    public void update(TkGradeDict tkGradeDict) throws Exception {
		tkGradeDict.setModifiedTime(new Date());
		tkGradeDictService.updateCheckName(tkGradeDict.getGradeId(),tkGradeDict.getGradeName());
        tkGradeDictService.update(tkGradeDict);
    }

    @ApiOperation(value = "删除年级字典", notes = "删除年级字典")
    @ApiImplicitParam(name = "id", value = "年级字典ID", required = true, paramType = "query", dataType = "String")
    @PostMapping("/delete")
    public void deleteTkGradeDict(TkGradeDict tkGradeDict) {
        tkGradeDictService.delete(tkGradeDict);
    }
    
}